<?php
/**
 * XIE--Scorpion
 *
 * 职位发布
 * 
 */
namespace App\Models\Admin;

use App\Http\Controllers\Controller;
use DB,Session,Url,Input,Request,Redirect;
use Illuminate\Database\Eloquent\Model;

class Postoffice extends Model
{
    protected $table = 'post_message';

    public $timestamps = false;

	  /*
     *职位发布列表
     */
    static function postofficelists()
    {
      $eid=Session::get('eid');
      $data=DB::table('post_message')->join('position','position.position_id','=','post_message.position_id')->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')->join('pay','post_message.pay_id','=','pay.pay_id')->join('suffer','post_message.suffer_id','=','suffer.suffer_id')->join('background','post_message.background_id','=','background.background_id')->join('city','post_message.city_id','=','city.city_id')->where('post_message.enterprise_id',$eid)->paginate(3);
	  
      return $data;

    }

	  /*
     *职位发布
     */
    static function postofficeadds($arr)
    {
      
      if(DB::table('post_message')->insert($arr)){

        return true;

      }else{

        return false;

      }

    }
	  /*
     *职位发布
     */
    static function postofficeselect()
    {
      $data=DB::table('position')->get();
	    $arr['position']=$this->digui($data,0);
	    $arr['enterprise']=DB::table('enterprise')->get();
	    $data=json_encode($data);
	    $data=json_decode($data,true);

      return $arr; 

    }

	  /*
     *无限极 分类
     */
    public function digui($data,$position_parent=0)
	  {

        $child=array();

        foreach($data as $key=>$val)
		    {
          if($val->position_parent == $position_parent)
			    {
            $child[]=$val;
          }
        }
        foreach($child as $key1=>$v)
		    {
            $current_child=$this->digui($data,$v->position_id);
            $child[$key1]->child=$current_child;
        }

        return $child;
    }

	  /*
     *职位发布列表删除
     */
    static function postofficedeletes($message_id)
    {
      
      if(DB::table('post_message')->where('message_id',$message_id)->delete()){

        return true;

      }else{

        return false;

      }
     
    }
	

    /*
     *职位发布列表修改查数据
     */
    static function postofficeupdates($message_id)
    {

      $arr=DB::table('post_message')->join('position','position.position_id','=','post_message.position_id')->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')->join('pay','post_message.pay_id','=','pay.pay_id')->join('suffer','post_message.suffer_id','=','suffer.suffer_id')->join('background','post_message.background_id','=','background.background_id')->join('city','post_message.city_id','=','city.city_id')->where('message_id',$message_id)->get();
	    
      return $arr;

    }


	  /*
     *职位发布列表修改保存
     */
    static function postofficesaves($message_id,$arr)
    {

      if(DB::table('post_message')->where('message_id',$message_id)->update($arr)){

        return true;

    	}else{

        return false;

    	}
    }
} 